home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d978.lha / MouseClock / Source / SmallStartup.i < prev   
Text File  |  1994-04-03  |  3KB  |  114 lines

  1. ; SmallStartup.i  v1.1  by  Adriano De Minicis 
  2. ;
  3. ; This startup code is Public Domain.
  4. ;
  5. ; Modified version of easystart.i
  6. ; Assembler used: Devpac 3
  7. ;
  8. ; IMPORTANT: Include this file at the end of include file list, but before
  9. ;            the beginning of your program (otherwise don't works!)
  10. ;
  11. ; This startup opens dos.library, and calls your program with "bsr main",
  12. ; with the following variables initialized:
  13. ;
  14. ; CmdLineLen:   Command line lenght (CLI)
  15. ; CmdLinePtr:    Command line pointer (CLI). Points to first non-space char.
  16. ;               (Ending spaces are not removed!)
  17. ;               Command line is always terminated by $0A (Line feed).
  18. ;
  19. ; OutputFH:    File handle for CLI output (NULL from WB)
  20. ;
  21. ; WBenchMsg:    Pointer to WBStartup struct if called from WB,
  22. ;               NULL if called from CLI.
  23. ;
  24. ; _SysBase:    exec.library pointer
  25. ; _DOSBase:    dos.library pointer
  26. ;
  27. ;
  28. ; NOTE: Before exiting from main, put in D7 the return code that must be
  29. ;       passed to CLI (zero if OK, otherwise error)
  30. ;
  31. ; NOTE: You can exit at any moment calling Exit (also from nested function
  32. ;       calls, because it restore the stack pointer to initial value),
  33. ;       but obviously you must close/release all stuff you've opened or
  34. ;       allocated (except dos.library).
  35. ;       Put in D7 the return code.
  36. ;
  37.  
  38.         IFND    EXEC_EXEC_I
  39.         include    exec/exec.i
  40.         ENDC
  41.         IFND    LIBRARIES_DOSEXTENS_I
  42.         include    libraries/dosextens.i
  43.         ENDC
  44.  
  45.  
  46. AbsExecBase    equ    4
  47.  
  48.  
  49. EntryPoint    move.l    sp,InitialSP        ; save stack pointer
  50.         move.l    d0,CmdLineLen        ; and command line
  51.         move.l  a0,CmdLinePtr        ; parameters
  52.  
  53.         move.l    AbsExecBase,_SysBase    ; save exec.lib pointer
  54.         lea    DOSName(pc),a1
  55.         moveq    #0,d0
  56.         CALLEXEC OpenLibrary        ; open DOS library
  57.         move.l    d0,_DOSBase        ; save dos.lib pointer
  58.         beq.s    ByeBye
  59.  
  60.         sub.l    a1,a1
  61.         CALLEXEC FindTask        ; find us
  62.         move.l    d0,a4
  63.  
  64.         tst.l    pr_CLI(a4)        ; run from WB?
  65.         beq.s    RunFromWB
  66.         
  67. RunFromCLI    CALLDOS    Output
  68.         move.l    d0,OutputFH        
  69.         bra.s    CallMain
  70.  
  71. RunFromWB    lea    pr_MsgPort(a4),a0
  72.         CALLEXEC WaitPort        ; wait for a message
  73.         lea    pr_MsgPort(a4),a0
  74.         CALLEXEC GetMsg            ; then get it
  75.         move.l    d0,WBenchMsg        ; save it for later reply
  76.  
  77. ; ---- Call our program ------------------------------------------------
  78.  
  79. CallMain    bsr    main
  80.  
  81. ; ---- Returns to here with exit code in d7 ----------------------------
  82.  
  83. Exit        move.l    _DOSBase(pc),a1
  84.         CALLEXEC CloseLibrary        ; Close DOS library
  85.  
  86.         tst.l    WBenchMsg        ; called from CLI?
  87.         beq.s    ByeBye
  88.  
  89.         CALLEXEC Forbid
  90.         move.l    WBenchMsg(pc),a1    ; reply to WB
  91.         CALLEXEC ReplyMsg
  92.  
  93. ByeBye        move.l    InitialSP,sp        ; restore stack pointer
  94.         move.l    d7,d0            ; exit code
  95.         rts
  96.  
  97. ;-----  startup code variables  -------------------------------------------
  98.  
  99. DOSName        dc.b    'dos.library'
  100.  
  101. _DOSBase    dc.l    0
  102. _SysBase    dc.l    0
  103.  
  104. WBenchMsg    dc.l    0    ; null if called from CLI, or no output
  105. OutputFH    dc.l    0    ; null if called from WB
  106.  
  107. InitialSP    dc.l    0
  108. CmdLineLen    dc.l    0
  109. CmdLinePtr    dc.l    0
  110.  
  111. ; the program starts here
  112.         even
  113.  
  114.